package it.gestoreContratti.gui.frames;

import it.gestoreContratti.database.DatabaseController;
import it.gestoreContratti.database.exception.DatabaseConnectionException;
import it.gestoreContratti.database.exception.QueryException;
import it.gestoreContratti.entity.Contratto;
import it.gestoreContratti.gui.panels.ContrattiScadenzaPanel;
import it.gestoreContratti.gui.panels.ModificaContrattoPanel;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class ModificaContrattoFrame extends JFrame {

	private static final long serialVersionUID = -9163350828726161384L;
	private JPanel contentPane;	
	private ModificaContrattoPanel modificaContrattoPanel;

	
	private DatabaseController databaseController;
	private Contratto contratto;
	private ContrattiScadenzaPanel panello;

	public ModificaContrattoFrame(ContrattiScadenzaPanel panel) throws DatabaseConnectionException, QueryException {
		this.panello = panel;
		this.databaseController = panello.getDatabaseController();
		this.contratto = panello.getSelectedContratto();
				
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				panello.refresh();				
			}
		});
		
		setTitle("Modifica Contratto Numero :"+contratto.getNumero().toString());
		setResizable(false);
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setSize(800, 600);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[]{0, 0};
		gbl_contentPane.rowHeights = new int[]{0, 0};
		gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gbl_contentPane.rowWeights = new double[]{1.0, Double.MIN_VALUE};
		contentPane.setLayout(gbl_contentPane);
		
		modificaContrattoPanel = new ModificaContrattoPanel(databaseController, contratto);		
		GridBagConstraints gbc_nuovoContrattoPanel = new GridBagConstraints();
		gbc_nuovoContrattoPanel.fill = GridBagConstraints.BOTH;
		gbc_nuovoContrattoPanel.gridx = 0;
		gbc_nuovoContrattoPanel.gridy = 0;
		contentPane.add(modificaContrattoPanel, gbc_nuovoContrattoPanel);
	}

	
	
	

}
